package yelmor.comm100.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import yelmor.comm100.domain.CoUser;
import yelmor.comm100.repository.CoUserRepository;
import yelmor.comm100.util.SecurityUtil;

/**
 * Created by yel on 4/27/16.
 */
@Controller
public class UserController {

  @Autowired
  private CoUserRepository coUserRepository;

  @RequestMapping(path="/user/basic")
  public String user(Model model) {
    String curUserName = SecurityUtil.getCurrentUserName();
    if(curUserName.equals("anonymousUser")) {
      model.addAttribute("notLogin", true);
    } else {
      model.addAttribute("userName", curUserName);
      CoUser coUser = coUserRepository.findOne(curUserName);
      model.addAttribute("coUser", coUser);
    }
    return "basic";
  }

  @RequestMapping(path="/user/serviceManage")
  public String serviceManage(Model model) {
    String curUserName = SecurityUtil.getCurrentUserName();
    if(curUserName.equals("anonymousUser")) {
      model.addAttribute("notLogin", true);
    } else {
      model.addAttribute("userName", curUserName);
      CoUser coUser = coUserRepository.findOne(curUserName);
      model.addAttribute("coUser", coUser);
    }
    return "serviceManage";
  }

 /* @RequestMapping(path="/user/report")
  public String report(Model model) {
    String curUserName = SecurityUtil.getCurrentUserName();
    if(curUserName.equals("anonymousUser")) {
      model.addAttribute("notLogin", true);
    } else {
      model.addAttribute("userName", curUserName);
      CoUser coUser = coUserRepository.findOne(curUserName);
      model.addAttribute("coUser", coUser);
    }
    return "report";
  }

  @RequestMapping(path="/user/imgConfig")
  public String imgConfig(Model model) {
    String curUserName = SecurityUtil.getCurrentUserName();
    if(curUserName.equals("anonymousUser")) {
      model.addAttribute("notLogin", true);
    } else {
      model.addAttribute("userName", curUserName);
      CoUser coUser = coUserRepository.findOne(curUserName);
      model.addAttribute("coUser", coUser);
    }
    return "imgConfig";
  }*/


}
